package com.example.laboratory.ui.core.model.impl;

import com.example.laboratory.bean.Items;
import com.example.laboratory.bean.Laboratory;
import com.example.laboratory.bean.UserList;
import com.example.laboratory.manager.UserInfoManager;
import com.example.laboratory.net.RxSchedulers;
import com.example.laboratory.net.callback.RxObserver;
import com.example.laboratory.ui.core.model.ILaboratoryModel;
import com.google.gson.Gson;
import okhttp3.RequestBody;

public class LaboratoryModel extends CommonModel implements ILaboratoryModel {
    @Override
    public void addLabs(Laboratory.RowsBean rowsBean, RxObserver<String> callback) {
        Gson gson=new Gson();
        String strEntity = gson.toJson(rowsBean);
        RequestBody body = RequestBody.create(okhttp3.MediaType.parse("application/json;charset=UTF-8"),strEntity);
        doRxRequest()
                .addLaboratory(body)
                .compose(RxSchedulers.<String>io_main())
                .subscribe(callback);
    }

    @Override
    public void getItemsByBelong(String belong, RxObserver<Items> rxObserver) {
        doRxRequest()
                .getItemsByBelong("Bearer "+ UserInfoManager.getUserInfo().getToken(),belong)
                .compose(RxSchedulers.<Items>io_main())
                .subscribe(rxObserver);

    }
    @Override
    public void getUsersByDepartId(String departId, String permission, RxObserver<UserList> rxObserver) {
        doRxRequest()
                .getUsersByDepartId("Bearer "+ UserInfoManager.getUserInfo().getToken(),departId,permission)
                .compose(RxSchedulers.<UserList>io_main())
                .subscribe(rxObserver);
    }
}
